App({
  getToken() {
    let that = this;
    return new Promise((resolve, reject) => {
      //获取当前用用户的授权状态
      wx.getSetting({
        success: function(res) {
          console.log(res.authSetting['scope.userInfo'])
          if (res.authSetting['scope.userInfo']) {
            // console.log(1111111111) 
            wx.getUserInfo({
              success: function(res) {
                // console.log(res);
                let info = res
                that.globalData.userInfo = {
                  userName: res.userInfo.nickName,
                  headImgUrl: res.userInfo.avatarUrl
                }
                wx.login({
                  success: res => {
                    // console.log(res)
                    wx.request({
                      url: 'https://api.mokyun.com/wxusers/authenticate/miniProgram',
                      method: 'POST',
                      data: {
                        code: res.code
                      },
                      header: {
                        APPID: 28
                      },
                      success(res) {
                        // console.log(res)
                        if (res.data.token) {
                          wx.setStorageSync('token', res.data.token)
                          resolve(info)
                        }
                      }
                    })
                  }
                })
              }
            });
          } else {
          //  console.log(222222222222) 
            reject(11);
          }
        }
      })
    })
  },
  globalData: {
    userInfo: null,
    first: null
  }
})